// eslint-disable-next-line
import { UserLayout, BasicLayout, BlankLayout } from '@/layouts'
// import { bxAnaalyse } from '@/core/icons'
// import storage from 'store'

const RouteView = {
  name: 'RouteView',
  render: h => h('router-view')
}

export const asyncRouterMap = (_menu) => {
  const menu = _menu || []
  const baseRouters =
    [
      {
        path: '/',
        name: 'index',
        component: BasicLayout,
        meta: { title: 'menu.home' },
        redirect: '/account/center'
      },
      {
        path: '*',
        redirect: '/404',
        hidden: true
      }
    ]
  const routers = [
    menu && menu.indexOf('ROLE_cat:user') !== -1 && {
      path: '/staff',
      name: 'staff',
      component: RouteView,
      redirect: '/staff/staffList',
      meta: { title: '员工管理', icon: 'user' },
      children: [
        menu && menu.indexOf('ROLE_page:user') !== -1 && {
          path: '/staff/staffList',
          name: 'staffList',
          component: () => import('@/views/staff/StaffList'),
          meta: { title: '员工列表', keepAlive: true }
        }
      ]
    },
    // customer
    menu && menu.indexOf('ROLE_cat:customer') !== -1 && {
      path: '/customer',
      name: 'customer',
      component: RouteView,
      redirect: '/customer/customerList',
      meta: { title: '客户管理', icon: 'team' },
      children: [
        menu && menu.indexOf('ROLE_page:customer') !== -1 && {
          path: '/customer/customerList',
          name: 'customerList',
          component: () => import('@/views/customer/CusotmerList'),
          meta: { title: '客户列表', keepAlive: true }
        }
      ]
    },
    // supplier
    menu && menu.indexOf('ROLE_cat:supplier') !== -1 && {
      path: '/supplier',
      name: 'supplier',
      component: RouteView,
      redirect: '/supplier/supplierList',
      meta: { title: '代理商管理', icon: 'shop' },
      children: [
        menu && menu.indexOf('ROLE_page:supplier') !== -1 && {
          path: '/supplier/supplierList',
          name: 'supplierList',
          component: () => import('@/views/supplier/Supplier'),
          meta: { title: '代理商管理', keepAlive: true }
        }
      ]
    },
    // baseData
    menu && menu.indexOf('ROLE_cat:supplier') !== -1 && {
      path: '/baseData',
      name: 'baseData',
      component: RouteView,
      redirect: '/baseData/baseDataList',
      meta: { title: '基础数据管理', icon: 'shop' },
      children: [
        menu && menu.indexOf('ROLE_page:supplier') !== -1 && {
          path: '/baseData/baseDataList',
          name: 'baseDataList',
          component: () => import('@/views/baseData/BaseData'),
          meta: { title: '基础数据列表', keepAlive: true }
        }
      ]
    },
    // demand
    menu && menu.indexOf('ROLE_cat:supplier') !== -1 && {
      path: '/demand',
      name: 'demand',
      component: RouteView,
      redirect: '/demand/demandList',
      meta: { title: '充值需求管理', icon: 'shop' },
      children: [
        menu && menu.indexOf('ROLE_page:supplier') !== -1 && {
          path: '/demand/demandList',
          name: 'demandList',
          component: () => import('@/views/demand/Demand'),
          meta: { title: '充值需求列表', keepAlive: true }
        }
      ]
    },
    // permission
    menu && menu.indexOf('ROLE_cat:role') !== -1 && {
      path: '/permission',
      name: 'permission',
      component: RouteView,
      redirect: '/permission/permissionList',
      meta: { title: '权限管理', icon: 'lock' },
      children: [
        menu && menu.indexOf('ROLE_page:role') !== -1 && {
          path: '/permission/permissionList',
          name: 'permissionList',
          component: () => import('@/views/permission/Permission'),
          meta: { title: '权限配置', keepAlive: true }
        }
      ]
    }
  ]
  const _resRouters = routers.filter(item => { if (item) return item })
  _resRouters.forEach(element => {
    element.children = element.children.filter(item => { if (item) return item })
  })
  baseRouters[0].children = _resRouters
  return baseRouters
}
/**
 * 基础路由
 * @type { *[] }
 */
export const constantRouterMap = [
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/login',
    hidden: false,
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/Login')
      }
    ]
  },
  /// account/center
  {
    path: '/account',
    name: 'index',
    component: BasicLayout,
    meta: { title: '我的信息' },
    redirect: '/account/center',
    children: [
      {
        path: 'center',
        name: 'center',
        meta: { title: '个人信息' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/account/center')
      }
    ]
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404')
  }
]
